package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizMemberGrade;
import com.member.shop.domain.SysBizMessage;
import com.member.shop.service.ISysBizMessageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【消息】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2025-01-08
 **/
@RestController
@RequestMapping("/shop/message")
public class SysBizMessageController extends BaseController {
    @Resource
    private ISysBizMessageService sysBizMessageService;

    private void setTenantId(SysBizMessage sysBizMessage) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizMessage.setTenantId(tenantId);
        }
    }

    /**
     * 查询消息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizMessage sysBizMessage) {
        startPage();
        setTenantId(sysBizMessage);
        List<SysBizMessage> list = sysBizMessageService.selectSysBizMessageList(sysBizMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:message:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizMessage sysBizMessage) {
        LambdaQueryWrapper<SysBizMessage> queryWrapper = new LambdaQueryWrapper<SysBizMessage>();
        List<SysBizMessage> list = sysBizMessageService.selectSysBizMessageList(queryWrapper);
        ExcelUtil<SysBizMessage> util = new ExcelUtil<SysBizMessage>(SysBizMessage.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizMessageService.selectSysBizMessageById(id));
    }

    /**
     * 新增消息
     */
    @PreAuthorize("@ss.hasPermi('shop:message:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizMessage sysBizMessage) {
        return toAjax(sysBizMessageService.insertSysBizMessage(sysBizMessage));
    }

    /**
     * 修改消息
     */
    @PreAuthorize("@ss.hasPermi('shop:message:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizMessage sysBizMessage) {
        return toAjax(sysBizMessageService.updateSysBizMessage(sysBizMessage));
    }

    /**
     * 删除消息
     */
    @PreAuthorize("@ss.hasPermi('shop:message:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizMessageService.deleteSysBizMessageByIds(ids));
    }
}
